package com.sari.common.config;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.sari.common.utils.PropertiesLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * 全局配置类
 */
public class Global {
    private static Logger logger = LoggerFactory.getLogger(Global.class);

    /**
     * 保存全局属性值
     */
    private static Map<String, String> map = Maps.newHashMap();

//    public static FFmpegManager ffmpegManager=new FFmpegManagerImpl();

    /**
     * 获取JSON字符串标识
     */
    final public static String JsonKey = "json_data";

    final public static String apiAddr = "";
    final public static String apiAddrHttps = "";
    final public static JSONObject videoUrls = new JSONObject();

    //
    final public static String httpsPath = "";

    /**
     * 属性文件加载对象
     */
    private static PropertiesLoader propertiesLoader = new PropertiesLoader("application.properties");

    /**
     * 获取配置
     */
    public static String getConfig(String key) {
        String value = map.get(key);
        if (value == null) {
            value = propertiesLoader.getProperty(key);
            try {
                //进行编码转换，解决中文乱码问题
                value = new String(value.getBytes("ISO8859-1"), "GBK");
            } catch (UnsupportedEncodingException e) {
                logger.warn("编码转换错误:" + value, e);
            }
            map.put(key, value);
        }
        return value;
    }

    /////////////////////////////////////////////////////////

    /**
     * 获取管理端根路径
     */
    public static String getAdminPath() {
        return getConfig("adminPath");
    }


}
